import * as PIXI from 'pixi.js'
export default (textureSource: PIXI.TextureSource) => {
  // 消耗
  const consumeArr: string[] = ['1', '2', '3', '4', '5', '6', '7+']
  const xnum = 2
  let xi = xnum
  const container = new PIXI.Container()
  consumeArr.forEach((item, index, arr) => {
    const consumeContainer = new PIXI.Container()
    // 背景
    const bgSprite = new PIXI.Sprite(
      new PIXI.Texture({
        source: textureSource,
        frame: new PIXI.Rectangle(1340, 1532, 116, 126),
      }),
    )
    bgSprite.anchor.set(0.5)
    bgSprite.scale.set(0.8)
    consumeContainer.addChild(bgSprite)
    // 衬层1
    const liningSprite1 = new PIXI.Sprite(
      new PIXI.Texture({
        source: textureSource,
        frame: new PIXI.Rectangle(97, 147, 70, 70),
      }),
    )
    liningSprite1.anchor.set(0.5)
    liningSprite1.position.set(-5, 5)
    liningSprite1.scale.set(0.8)
    consumeContainer.addChild(liningSprite1)
    // 衬层2
    const liningSprite2 = new PIXI.Sprite(
      new PIXI.Texture({
        source: textureSource,
        frame: new PIXI.Rectangle(873, 341, 70, 70),
      }),
    )
    liningSprite2.anchor.set(0.5)
    liningSprite2.position.set(-5, 5)
    liningSprite2.scale.set(0.8)
    consumeContainer.addChild(liningSprite2)

    // 数字
    const val = new PIXI.Text({
      text: item,
      style: {
        fontFamily: 'RZFont',
        fontSize: 40,
        fill: 0xffffff,
        align: 'center',
      },
    })
    val.anchor.set(0.5)
    val.position.set(-5, 5)
    consumeContainer.addChild(val)
    consumeContainer.position.set(0, 0)
    // 55 - 衬层的高度
    if (arr.length % xnum !== 0 && xi === xnum && index === arr.length - (arr.length % xnum)) {
      xi = arr.length % xnum
    }
    consumeContainer.position.set(
      -322 / 2 + (322 / xi) * (0.5 + (index % xi)),
      366 * 1.1 + 50 / 2 + ((481 * 1.1) / Math.ceil(arr.length / xnum)) * (0.5 + Math.floor(index / xnum)),
    )
    container.addChild(consumeContainer)
  })
  return container
}
